let vm = new Vue({
   el:'.main-content',
    data:{
       username:'',
       password:'',
       code:'',
        render:'kaptcha/render'
    },
    methods:{
       
       //点击更新验证码
        refresh:function(){
            this.render=`kaptcha/render?`+new Date();
        },
        login:function () {
            axios({
                url:`main/login`,
                params:{username: this.username,password: this.password,code: this.code}
            }).then(response=>{
                if(!response.data.success){
                    //失败
                    layer.msg(response.data.msg);

                    this.refresh();
                }else {
                    //成功
                    location.href=`index.html`;
                    //json转字符串
                    let map = JSON.stringify(response.data.obj);
                    sessionStorage.setItem("map",map)
                }
            }).catch(error=>{
                layer.msg(error.message);
            })
        }
    }
});
